﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<% New obj = (New)ViewData.Model; %>
<script src="/Scripts/ckeditor/ckeditor.js" type="text/javascript"></script>
<script type="text/javascript">
    var formIndex = 0;
//    function DeleteImage(id) {
//        var obj = $("#" + id);
//        obj.html("");
//        obj.append("<input type='file' name='file' id='file' size='60'");
//    }
    $(document).ready(function () {
        CKEDITOR.replace('NewsContent', {
            filebrowserImageUploadUrl: '/Administration/Common/UploadImage',
            filebrowserFlashUploadUrl: '/Administration/Common/UploadFlash',
            entities: false
        });
        $("#cancel").click(function () {
            window.location = "/Administration/News/";
        });
        $("#addForm").validate({
            debug: false,
            errorElement: "span",
            errorPlacement: function (error, element) {
                error.tooltip({
                    bodyHandler: function () {
                        return error.html();
                    }
                });
                error.insertAfter(element);
            },
            rules: {
                Title: { required: true },
                Description: { required: true },
                PostedDate: { required: true, checkDate: true },
                Author: { required: true }
                
            },
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    success: function (result) {
                        if (result.MsgType == 1) {
                            JS_LIB.msgBox(result.MsgText, "400");
                        }
                        else {
                            //CKEDITOR.instances.TestContent.destroy();
                            window.location = "/Administration/News/Index";
                        }
                    },
                    url: form.action,
                    dataType: 'json',
                    cache: false,
                    iframe: true
                });

            }
        });
    });
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="edit">
<%
    if (ViewData.Model != null)
    {%>
        <tr>
            <td class="label">
                Mã tin tức
            </td>
            <td class="input">
                <%=obj.ID %>
            </td>
        </tr>
    <%}
     %>
    <tr>
        <td class="label required">
            Tiêu đề <span>*</span>
        </td>
        <td class="input">
            <% if (ViewData.Model == null)
               {
                   Response.Write(Html.TextBox("Title", "", new { @maxlength = "100",@style="width:80%" }));
               }
               else
               {
                   Response.Write(Html.TextBox("Title", obj.Title, new { @maxlength = "100", @style = "width:80%" }));
               }
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Mô tả
        </td>
        <td class="input">
            <% if (ViewData.Model == null)
               {
                   Response.Write(Html.TextBox("Description", "", new { @maxlength = "255", @style = "width:80%" }));
               }
               else
               {
                   Response.Write(Html.TextBox("Description", obj.Description, new { @maxlength = "255", @style = "width:80%" }));
               }
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Hình ảnh
        </td>        
        <td class="input" id="tdImage">
            <% if (ViewData.Model == null)
               {
                   Response.Write("<input type='file' name='file' id='file' size='60'");
               }
               else
               {
                   string urlImage = Constants.UPLOAD_IMAGE_PATH + obj.Image;
                   if (obj.Image != String.Empty)
                       Response.Write("<img src='" + urlImage + "' width='100' height='100'/><br/>");
                   Response.Write("<input type='file' name='file' id='file' size='60'");
                   Response.Write(Html.Hidden("Image", obj.Image));
               }
            %>
        </td>
    </tr>
    
    <tr>
        <td class="label">
            Ngày tạo
        </td>
        <td class="input">
            <% if (ViewData.Model == null)
               {
                   Response.Write(Html.DatePicker("PostedDate", DateTime.Now.ToString(Constants.DATETIME_FORMAT), new {@style="width:150px" }));
               }
               else
               {
                   Response.Write(Html.DatePicker("PostedDate", obj.PostedDate.HasValue ? obj.PostedDate.Value.ToString(Constants.DATETIME_FORMAT) : string.Empty));
               }
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Tác giả
        </td>
        <td class="input">
            <% if (ViewData.Model == null)
               {
                   Response.Write(Html.TextBox("Author", ViewData["Author"], new { @maxlength = "200", @style = "width:170px" }));
               }
               else
               {
                   Response.Write(Html.TextBox("Author", obj.Author, new { @maxlength = "200", @style = "width:170px" }));
               }
            %>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Nội dung <span>*</span>
        </td>
        <td class="input">
            <% if (ViewData.Model == null)
               {
                   Response.Write(Html.TextArea("NewsContent"));
               }
               else
               {
                   Response.Write(Html.TextArea("NewsContent", CommonFunc.SetHtmlForCKEditor(obj.NewsContent)));
               }
            %>
        </td>
    </tr>
    <tr>
        <td colspan="2" align="center">
            <input type="submit" class="save" value="" alt="" />
            <input type="button" class="cancel" value="" alt="" id="cancel" />
        
        </td>
    </tr>
</table>
